-- @owner: @zou_jialiang050
-- @date: 2022/02/24
-- @testpoint: 在视图上创建update of on before触发器，合理报错

--step1:建表;expect:成功
drop table if exists t_trigger_src cascade;
drop table if exists t_trigger_des cascade;
create table t_trigger_src(id1 int, id2 int, id3 int) with (storage_type=ustore);
create table t_trigger_des(id1 int, id2 int, id3 int) with (storage_type=ustore);

--step2:在视图上创建update of on before触发器;expect:合理报错
create or replace view t_trigger_src_view1 as select * from t_trigger_src;
create or replace function tri_update_func() returns trigger as
$$
declare
begin
update t_trigger_des set id3=new.id3 where id1 in (select id1 from t_trigger_src order by id1 limit 1);
return old;
end
$$ language plpgsql;
/
drop trigger if exists delete_trigger on t_trigger_src_view1;
create trigger delete_trigger before update of id3 on t_trigger_src_view1
for each row
execute procedure tri_update_func();
/

--step3:清理环境;expect:成功
drop table if exists t_trigger_src cascade;
drop table if exists t_trigger_des cascade;